package kgame5.pbe.atlantic.manager {
	import kgame5.k25d.core.Camera25D;
	import kgame5.k25d.core.Node25D;
	import kgame5.k25d.core.group.FastGroup25D;
	import kgame5.k25d.core.group.GoodGroup25D;
	import kgame5.k25d.core.group.Group25D;
	import kgame5.k25d.core.group.World25D;
	import kgame5.k25d.helper.MouseInput25D;
	import kgame5.pbe.engine.core.IAnimatedObject;

	import flash.display.Sprite;
	import flash.utils.Dictionary;

	/**
	 * @author max
	 * 2010-12-13
	 * 
	 * 游戏视图管理器,
	 * TODO 考虑是否再此作拖拽
	 */
	public class View25DManager implements IAnimatedObject {
		
		//区分图层，这样为了减少排序，比如地面是不需要排序的，节约运算量
		public static const 
			LAYER_GROUND:int=0,
			LAYER_BUILDING:int=1,
			LAYER_SKY:int=2;
		
		private var world : World25D;
		public var camera:Camera25D;
		
		public var mouseInput:MouseInput25D;//拖拽屏幕用的
		
		
		private var dict_layer:Dictionary;
		
		public function View25DManager() {
			
		}
		
		public function Init(mc_c:Sprite,viewWidth:int,viewHeight:int):void{
			world =new World25D();
			mc_c.addChild(world.getDO());
			
			camera = world.camera;
			camera.viewRect.width=viewWidth;
			camera.viewRect.height=viewHeight;
			
			
			mouseInput=new MouseInput25D(world);
			
			dict_layer=new Dictionary();
			
//			//添加两层，一个排序，一个不排序
			var groundLayer:Group25D=new FastGroup25D();
			var buildingLayer:Group25D=new GoodGroup25D();//
			var skyLayer:Group25D=new FastGroup25D();
			
			dict_layer[LAYER_GROUND]=groundLayer;
			dict_layer[LAYER_BUILDING]=buildingLayer;
			dict_layer[LAYER_SKY]=skyLayer;
			
			world.addChild(groundLayer);
			world.addChild(buildingLayer);
			world.addChild(skyLayer);
			
			world.getDO().cacheAsBitmap=true;
		}

		
		public function onFrame(deltaTime : Number) : void {
			//world25D.camera.target.x++;
			world.update(null);
		}
		
		public function addNode(node:Node25D):void{
			if(node._layerID==-1){
				throw new Error("请设置此节点的layerID");
			}
			(dict_layer[node._layerID] as Group25D).addChild(node);
			
		}
		
		public function removeNode(node:Node25D):void{
			(dict_layer[node._layerID] as Group25D).removeChild(node);
			
		}
	}//end of class
}
